package com.zeng.stpro.commons.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author ZENGZHIJUN
 * @Date 2021/2/2 14:56
 *
 * 统一返回 信息
 */
public class R {

    private static final int OK_CODE = 200;//HttpStatus.SC_OK
    private static final int NG_CODE = 100;//no goog

    private int code;
    private String msg;
    private Map<String, Object> data = new HashMap<>();

    public static R ng() {
        return R.ng("error");
    }
    public static R ng(String ngMsg) {
        return new R(NG_CODE, ngMsg);
    }
    public static R ng(String ngMsg, int code) {
        return new R(code, ngMsg);
    }
    public static R ok() {
        return new R(OK_CODE, "success");
    }
    public static R ok(String okMsg) {
        return new R(OK_CODE, okMsg);
    }

    public R data(String k, Object v) {
        this.getData().put(k, v);
        return this;
    }



    //
    private R() {}
    private R(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    private void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    private void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getData() {
        return data;
    }

    private void setData(Map<String, Object> data) {
        this.data = data;
    }
}
